var $tablePaper = $('#tablePaper')
var $removePaper = $('#removePaper')
var paperSelections = []

function typeFormatterPaper(value) {
    if (value == 0) {
        return '随机出题';
    } else if (value == 1) {
        return '固定出题';
    }
}

function timeFormatterPaper(value) {
    return value + '分钟';
}

function scoreFormatterPaper(value) {
    return value + '分';
}

function qstNumFormatterPaper(value) {
    return value + '道';
}

function initTablePaper() {
    tableList2($tablePaper,[
        [{
            field: 'state',
            checkbox: true,
            align: 'center',
        }, {
            title: '试卷名称',
            field: 'name',
            // align: 'center'
        }, {
            title: '答题时间（分钟）',
            field: 'time',
            // align: 'center',
            // formatter: timeFormatterPaper
        }, {
            title: '试卷类型',
            field: 'type',
            // align: 'center',
            formatter: typeFormatterPaper
        }, {
            title: '试卷题数',
            field: 'qstNum',
            // align: 'center',
            // formatter: qstNumFormatterPaper
        }, {
            title: '试卷分数',
            field: 'score',
            // align: 'center',
            // formatter: scoreFormatterPaper
        }]
    ],function(){
        $removePaper.prop('disabled', !$tablePaper.bootstrapTable('getSelections').length)

        // save your data, here just save the current page
        paperSelections = getIdSelectionsPaper()
        // push or splice the paperSelections if you want to save all data paperSelections
    })
    $removePaper.click(function () {
        var ids = getIdSelectionsPaper()
        confirmAlert(function () {
            ajaxJson("/admin/exam/ajax/paper/delete", {"ids": ids.toString()}, function (res) {
                if (res.status) {
                    $removePaper.prop('disabled', true)
                    refreshTablePaper();
                }
            })
        })
    })
}

function refreshTablePaper(){
    $tablePaper.bootstrapTable('refresh');
}

function getIdSelectionsPaper() {
    return $.map($tablePaper.bootstrapTable('getSelections'), function (row) {
        return row.examPaperId
    })
}

$(function () {
    initTablePaper()
})